<!-- Table -->
<template>
  <div>
    <el-button
      type="primary"
      class="addhost"
      icon="el-icon-edit"
      @click="dialogFormVisible = true"
      >添加</el-button
    >
    <el-dialog title="添加主机" :visible.sync="dialogFormVisible">
      <el-form :model="form">
        <el-form-item label="主机IP" :label-width="formLabelWidth">
          <el-input v-model="form.hostip" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="主机名称" :label-width="formLabelWidth">
          <el-input v-model="form.hostname"> </el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogFormVisible = false">取 消</el-button>
        <el-button type="primary" @click="addhost">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<style scoped>
.addhost {
  display: flex;
  justify-content: flex-end;
}
</style>
<script>
    import Axios from 'axios';
    import qs from 'qs';
export default {

  data() {
    return {
      gridData: [],
      dialogFormVisible: false,
      form: {
        hostip: "",
        hostname: "",
        date1: "",
        date2: "",
        delivery: false,
        type: [],
        resource: "",
        desc: "",
      },
      formLabelWidth: "120px",
    };
  },
  methods:{
      addhost(){
         Axios.post(
        '/hosts/insert',
        qs.stringify({
          ip: this.hostip,
          name: this.hostname,
        })
      ).then((res) => {
        console.log(res);
        if (res.data.state == 0) {
          alert("Ip已存在");
        } else {
          alert("添加成功");
        }
      });  
      },
  },
};
</script>